package io.cici.cc.mybatis.lite.sql_source.scripting.tag;


import io.cici.cc.mybatis.lite.sql_source.Context;
import io.cici.cc.mybatis.lite.sql_source.scripting.ognl.ExpressionEvaluator;

public class IfTag implements Tag {
    private final ExpressionEvaluator expressionEvaluator;
    private final String test;
    private final Tag tag;

    public IfTag(String test, Tag tag) {
        this.test = test;
        this.tag = tag;
        this.expressionEvaluator = new ExpressionEvaluator();
    }

    @Override
    public boolean apply(Context context) {
        if (expressionEvaluator.evaluateBoolean(context.getBindings(), test)) {
            tag.apply(context);
            return true;
        }
        return false;
    }

}
